package org.jivesoftware.smackx.packet;

import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.util.StringUtils;

public class DiscoverInfo extends IQ
{
  public static final String NAMESPACE = "http://jabber.org/protocol/disco#info";
  private final List<Feature> features = new CopyOnWriteArrayList();
  private final List<Identity> identities = new CopyOnWriteArrayList();
  private String node;

  public DiscoverInfo()
  {
  }

  public DiscoverInfo(DiscoverInfo paramDiscoverInfo)
  {
    super(paramDiscoverInfo);
    setNode(paramDiscoverInfo.getNode());
    Iterator localIterator;
    Object localObject1;
    synchronized (paramDiscoverInfo.features)
    {
      localIterator = paramDiscoverInfo.features.iterator();
      while (localIterator.hasNext())
      {
        localObject1 = (Feature)localIterator.next();
        addFeature((Feature)localObject1);
      }
    }
    synchronized (paramDiscoverInfo.identities)
    {
      localIterator = paramDiscoverInfo.identities.iterator();
      while (localIterator.hasNext())
      {
        localObject1 = (Identity)localIterator.next();
        addIdentity((Identity)localObject1);
      }
    }
  }

  public void addFeature(String paramString)
  {
    addFeature(new Feature(paramString));
  }

  public void addFeatures(Collection<String> paramCollection)
  {
    if (paramCollection == null)
      return;
    Iterator localIterator = paramCollection.iterator();
    while (localIterator.hasNext())
    {
      String str = (String)localIterator.next();
      addFeature(str);
    }
  }

  private void addFeature(Feature paramFeature)
  {
    synchronized (this.features)
    {
      this.features.add(paramFeature);
    }
  }

  public Iterator<Feature> getFeatures()
  {
    synchronized (this.features)
    {
      return Collections.unmodifiableList(this.features).iterator();
    }
  }

  public void addIdentity(Identity paramIdentity)
  {
    synchronized (this.identities)
    {
      this.identities.add(paramIdentity);
    }
  }

  public void addIdentities(Collection<Identity> paramCollection)
  {
    if (paramCollection == null)
      return;
    synchronized (this.identities)
    {
      this.identities.addAll(paramCollection);
    }
  }

  public Iterator<Identity> getIdentities()
  {
    synchronized (this.identities)
    {
      return Collections.unmodifiableList(this.identities).iterator();
    }
  }

  public String getNode()
  {
    return this.node;
  }

  public void setNode(String paramString)
  {
    this.node = paramString;
  }

  public boolean containsFeature(String paramString)
  {
    Iterator localIterator = getFeatures();
    while (localIterator.hasNext())
      if (paramString.equals(((Feature)localIterator.next()).getVar()))
        return true;
    return false;
  }

  public String getChildElementXML()
  {
    StringBuilder localStringBuilder = new StringBuilder();
    localStringBuilder.append("<query xmlns=\"http://jabber.org/protocol/disco#info\"");
    if (getNode() != null)
    {
      localStringBuilder.append(" node=\"");
      localStringBuilder.append(StringUtils.escapeForXML(getNode()));
      localStringBuilder.append("\"");
    }
    localStringBuilder.append(">");
    Iterator localIterator;
    Object localObject1;
    synchronized (this.identities)
    {
      localIterator = this.identities.iterator();
      while (localIterator.hasNext())
      {
        localObject1 = (Identity)localIterator.next();
        localStringBuilder.append(((Identity)localObject1).toXML());
      }
    }
    synchronized (this.features)
    {
      localIterator = this.features.iterator();
      while (localIterator.hasNext())
      {
        localObject1 = (Feature)localIterator.next();
        localStringBuilder.append(((Feature)localObject1).toXML());
      }
    }
    localStringBuilder.append(getExtensionsXML());
    localStringBuilder.append("</query>");
    return localStringBuilder.toString();
  }

  public boolean containsDuplicateIdentities()
  {
    LinkedList localLinkedList = new LinkedList();
    Iterator localIterator1 = this.identities.iterator();
    while (localIterator1.hasNext())
    {
      Identity localIdentity1 = (Identity)localIterator1.next();
      Iterator localIterator2 = localLinkedList.iterator();
      while (localIterator2.hasNext())
      {
        Identity localIdentity2 = (Identity)localIterator2.next();
        if (localIdentity1.equals(localIdentity2))
          return true;
      }
      localLinkedList.add(localIdentity1);
    }
    return false;
  }

  public boolean containsDuplicateFeatures()
  {
    LinkedList localLinkedList = new LinkedList();
    Iterator localIterator1 = this.features.iterator();
    while (localIterator1.hasNext())
    {
      Feature localFeature1 = (Feature)localIterator1.next();
      Iterator localIterator2 = localLinkedList.iterator();
      while (localIterator2.hasNext())
      {
        Feature localFeature2 = (Feature)localIterator2.next();
        if (localFeature1.equals(localFeature2))
          return true;
      }
      localLinkedList.add(localFeature1);
    }
    return false;
  }

  public static class Feature
  {
    private String variable;

    public Feature(String paramString)
    {
      if (paramString == null)
        throw new IllegalArgumentException("variable cannot be null");
      this.variable = paramString;
    }

    public String getVar()
    {
      return this.variable;
    }

    public String toXML()
    {
      StringBuilder localStringBuilder = new StringBuilder();
      localStringBuilder.append("<feature var=\"").append(StringUtils.escapeForXML(this.variable)).append("\"/>");
      return localStringBuilder.toString();
    }

    public boolean equals(Object paramObject)
    {
      if (paramObject == null)
        return false;
      if (paramObject == this)
        return true;
      if (paramObject.getClass() != getClass())
        return false;
      Feature localFeature = (Feature)paramObject;
      return this.variable.equals(localFeature.variable);
    }

    public int hashCode()
    {
      return 37 * this.variable.hashCode();
    }
  }

  public static class Identity
    implements Comparable<Identity>
  {
    private String category;
    private String name;
    private String type;
    private String lang;

    public Identity(String paramString1, String paramString2)
    {
      this.category = paramString1;
      this.name = paramString2;
    }

    public Identity(String paramString1, String paramString2, String paramString3)
    {
      if ((paramString1 == null) || (paramString3 == null))
        throw new IllegalArgumentException("category and type cannot be null");
      this.category = paramString1;
      this.name = paramString2;
      this.type = paramString3;
    }

    public String getCategory()
    {
      return this.category;
    }

    public String getName()
    {
      return this.name;
    }

    public void setName(String paramString)
    {
      this.name = paramString;
    }

    public String getType()
    {
      return this.type;
    }

    public void setType(String paramString)
    {
      this.type = paramString;
    }

    public void setLanguage(String paramString)
    {
      this.lang = paramString;
    }

    public String getLanguage()
    {
      return this.lang;
    }

    public String toXML()
    {
      StringBuilder localStringBuilder = new StringBuilder();
      localStringBuilder.append("<identity");
      if (this.lang != null)
        localStringBuilder.append(" xml:lang=\"").append(StringUtils.escapeForXML(this.lang)).append("\"");
      localStringBuilder.append(" category=\"").append(StringUtils.escapeForXML(this.category)).append("\"");
      localStringBuilder.append(" name=\"").append(StringUtils.escapeForXML(this.name)).append("\"");
      if (this.type != null)
        localStringBuilder.append(" type=\"").append(StringUtils.escapeForXML(this.type)).append("\"");
      localStringBuilder.append("/>");
      return localStringBuilder.toString();
    }

    public boolean equals(Object paramObject)
    {
      if (paramObject == null)
        return false;
      if (paramObject == this)
        return true;
      if (paramObject.getClass() != getClass())
        return false;
      Identity localIdentity = (Identity)paramObject;
      if (!this.category.equals(localIdentity.category))
        return false;
      String str1 = localIdentity.lang == null ? "" : localIdentity.lang;
      String str2 = this.lang == null ? "" : this.lang;
      if (!str1.equals(str2))
        return false;
      String str3 = localIdentity.type == null ? "" : localIdentity.type;
      String str4 = this.type == null ? "" : this.type;
      if (!str3.equals(str4))
        return false;
      String str5 = localIdentity.name == null ? "" : localIdentity.name;
      String str6 = this.name == null ? "" : localIdentity.name;
      return str6.equals(str5);
    }

    public int hashCode()
    {
      int i = 1;
      i = 37 * i + this.category.hashCode();
      i = 37 * i + (this.lang == null ? 0 : this.lang.hashCode());
      i = 37 * i + (this.type == null ? 0 : this.type.hashCode());
      i = 37 * i + (this.name == null ? 0 : this.name.hashCode());
      return i;
    }

    public int compareTo(Identity paramIdentity)
    {
      String str1 = paramIdentity.lang == null ? "" : paramIdentity.lang;
      String str2 = this.lang == null ? "" : this.lang;
      String str3 = paramIdentity.type == null ? "" : paramIdentity.type;
      String str4 = this.type == null ? "" : this.type;
      if (this.category.equals(paramIdentity.category))
      {
        if (str4.equals(str3))
        {
          if (str2.equals(str1))
            return 0;
          return str2.compareTo(str1);
        }
        return str4.compareTo(str3);
      }
      return this.category.compareTo(paramIdentity.category);
    }
  }
}

/* Location:           D:\hygieia\userclient\common\libs\easemobchat_2.1.8.jar
 * Qualified Name:     org.jivesoftware.smackx.packet.DiscoverInfo
 * JD-Core Version:    0.6.1
 */